package cn.antblog.leetcode;

import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Set;

/**
 * @author YangJingyi
 * @date 2021-11-30 17:20
 */
public class Solution {
    public static void main(String[] args) {
        //回文数
        isPalindrome(100);
    }
    //回文数
    public static boolean isPalindrome(int x) {
        if(x < 0){
            return false;
        }
        int x2 = x ;
        int tmp = 0;
        while (x!=0){
            int i = x % 10;
            tmp = tmp*10+i;
            x = x/10;
        }
        if (tmp == x2){
            System.out.println("11111");
            return true;
        }else {
            System.out.println("0000000");
            return false;
        }
    }

    public int[] topKFrequent(int[] nums, int k) {
        int[] result = new int[k];
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }

        Set<Map.Entry<Integer, Integer>> entries = map.entrySet();
        // 根据map的value值正序排，相当于一个小顶堆
        PriorityQueue<Map.Entry<Integer, Integer>> queue = new PriorityQueue<>((o1, o2) -> o2.getValue() - o1.getValue());
        for (Map.Entry<Integer, Integer> entry : entries) {
            queue.offer(entry);
            if (queue.size() > k) {
                queue.poll();
            }
        }
        for (int i = k - 1; i >= 0; i--) {
            result[i] = queue.poll().getKey();
        }
        return result;
    }



}
